//package fileupdown;
//
//import cn.hutool.core.util.StrUtil;
//import com.baidu.Student;
//
//import javax.servlet.ServletException;
//import javax.servlet.annotation.WebServlet;
//import javax.servlet.http.HttpServlet;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.File;
//import java.io.IOException;
//import java.net.URLEncoder;
//import java.sql.Connection;
//import java.sql.PreparedStatement;
//import java.sql.ResultSet;
//import java.sql.Statement;
//import java.util.ArrayList;
//import java.util.List;
//
//@WebServlet("/index")
//public class Index extends HttpServlet {
//    @Override
//    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
////        super.service(req, resp);
//        //从数据库获取文件名
//        List<String> list = new ArrayList<>();
//        List<String> update = new ArrayList<>();
//        List<String> id = new ArrayList<>();
//        try {
//            Connection connection = JdcbConnection.requestConnection();
//            String sql = null;
//            if (StrUtil.isEmpty(req.getParameter("fileName"))){
//                sql = "select attachment_name,upload_date,file_id from file_table";
//            }else {
//                sql = "select attachment_name,upload_date,file_id from file_table where attachment_name= '"+req.getParameter("fileName")+"'";
//            }
//            Statement statement = connection.createStatement();
//            ResultSet resultSet = statement.executeQuery(sql);
//            while (resultSet.next()){
//                list.add(resultSet.getString("attachment_name"));
//                update.add(resultSet.getString("upload_date"));
//                id.add(resultSet.getString("file_id"));
//            }
//
//        }catch (Exception e){
//            e.printStackTrace();
//        }
//        // 设置分页参数
//        int pageSize = 5; // 每页显示的记录数
//        int currentPage = 1; // 当前页数，默认为第一页
//        String pageParam = req.getParameter("page");
//        if (pageParam != null && !pageParam.isEmpty()) {
//            currentPage = Integer.parseInt(pageParam);
//        }
//        // 计算分页的起始索引和结束索引
//        int startIndex = (currentPage - 1) * pageSize;
//        //获取最后一条数据
//        int endIndex = Math.min(startIndex + pageSize, list.size());
//        // 获取当前页的学生列表
//        List<String> list1 = list.subList(startIndex, endIndex);
//        List<String> list2 = update.subList(startIndex, endIndex);
//        List<String> list3 = id.subList(startIndex, endIndex);
//        req.setAttribute("currentPage", currentPage);
//        //获取总页数
//        req.setAttribute("totalPages", (int) Math.ceil((double) list.size() / pageSize));
//        req.setAttribute("nameList", list1);
//        req.setAttribute("dataList", list2);
//        req.setAttribute("idList", list3);
//        req.getRequestDispatcher("index.jsp").forward(req, resp);
//
//    }
//}
